{extend name="$BASE_POPUP_FORM" /}
{block name="body"}
<link rel="stylesheet" type="text/css" href="__STATIC__/easyui/themes/custom/easyui.css" />
<style>
    .edui-editor, .edui-editor-iframeholder {
        width: 790px !important;
    }
    .img_upload_wrp .img_upload_box.img_upload_preview_box{
        width:120px !important;
        height:120px !important;
    }

</style>
<div class="box-content">
    <input type="hidden" id="id" name="id" value="{$id}"/>
    <div class="control-group" id="video_on" style="">
            <label class="control-label">添加视频</label>
            <div class="controls">
                <button type="button" onclick="open_view()" class="btn btn-xs btn-default edit-btn"><i class="icon wb-edit"></i>添加视频</button>
                <input type="hidden" id="obj_id" name="obj_id" />
            </div>
        </div>
        <div class="control-group" style="">
            <label class="control-label">视频列表</label>
            <div class="controls" style="width:640px">  
                <table id="grid-table" style="width:100%"></table>
            </div>
        </div>

</div>
{/block}
{block name="script"}
<script type="text/javascript" src="__STATIC__/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="__STATIC__/easyui/src/datagrid-cellediting.js"></script> 
<script type="text/javascript" src="__STATIC__/easyui/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="__STATIC__/layer/laydate/laydate.js"></script>
<script type="text/javascript">

var current_index = -1;
var current_traffic = -1;
var rows ={$video_list};
$(function(){
    init_goods();
    for (var i = rows.length - 1; i >= 0; i--) {
        $('#grid-table').datagrid('insertRow', { row: rows[i]});
    }
})
function init_goods() {
    var columns = [
        {field: 'id',title:'视频id', width: 180, align: 'center'},
        {field: 'video_title', title: '视频标题', width: 180, align: 'center',},
        {field: 'video_img', title: '视频图片', width: 80, align: 'center',formatter:formatImg},
        {field: '_oper', title: '移除', width: 80, align: 'center', formatter: foramtOper}
    ];
    $('#grid-table').datagrid({
        method: "GET",
        // rownumbers: true,
        singleSelect: true,
        remoteSort: false,
        checkOnSelect: false,
        multiSort: false,
        emptyMsg: '<span>无相关数据</span>',
        pagination: false,
        columns: [columns],
    });
}

function formatImg(value, row, index) {
    html = '';
    if(value!=null){
        html = '<a href="'+value+'" target="_blank"><img src="'+value+'" style="max-width:50px;max-height:20px;text-align: center"></a>';
    }
    return html;
}
    // var video_list ={$video_list};
    // function openSearchWin(){
    //     var url = getURL('select_video','','task');
    //     openBarWinParent('选择视频', 500, 600, url, function (data) {
    //         console.log(data);
    //         $("#obj_id").setValue(data);
    //     }, ['选定', '取消']);
    // }
function open_view() {
    var url = getURL('select_video');
    openBarWin('添加视频', 600, 400, url, callback, ['保存', '取消']);
}

function callback(rows) {
    console.log(rows);
    for (var i = rows.length - 1; i >= 0; i--) {
        $('#grid-table').datagrid('insertRow', { row: rows[i]});
    }
}

function chkForm() {
    if (!makeJson()) {
        return false;
    }
    return true;
}
function makeJson(){
    var arr = ($('#grid-table').datagrid('getRows'));
    id_arr = new Array();
    for (var i = arr.length - 1; i >= 0; i--) {
        id_arr.push(arr[i]['id'])
        // Things[i]
    }
    console.log(id_arr)
    $('#obj_id').val(JSON.stringify(id_arr));
    return true;
}

function onLoadDataSuccess(data){
    setPicValue("image", data['image']);
    if(data['obj_video']){
        for (var i = data['obj_video'].length - 1; i >= 0; i--) {
            $('#grid-table').datagrid('insertRow', { row: data['obj_video'][i]});
        }
    }
}

function uploadImgCallback(path) {
    $("#image").val(path);
}
function onType() {
    var type = $("#type").val()
    if(type == 2){
        $("#video_on").show();
    }else {
        $("#video_on").hide();
    }
}


function foramtOper(value, row, index) {
    return '<i title="删除" onclick="delGoodsRow(this)" class="js_delRowBtn grid-row-del-btn icon wb-close"></i>';
}
function delGoodsRow(obj) {
    var index = $(obj).parent().parent().parent().attr('datagrid-row-index');
    $('#grid-table').datagrid('deleteRow', parseInt(index));
}


</script>
{/block}
